package com.example.blog.service.impl;

import com.example.blog.dao.UserMapper;
import com.example.blog.pojo.User;
import com.example.blog.service.UserService;
import com.example.blog.utils.SaltUtils;
import org.apache.shiro.crypto.hash.Md5Hash;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * name: 东北宋小宝
 * date: 2020/8/13
 */
@Service
public class UserServiceImpl implements UserService {
    @Resource
    private UserMapper userMapper;
    @Override
    public User chackUser(String username, String password) {
        Map map = new HashMap();
        map.put("username","root");
        map.put("password","root");
        User user =  userMapper.findUser(map);
        return user;
    }

    @Override
    public void saveUser(User user) {
        //生成盐
        String salt = SaltUtils.getSalt(8);
        //保存数据库
        user.setSalt(salt);
        //明文密码 MD5 + SALT + HASH散列
        Md5Hash md5Hash = new Md5Hash(user.getPassword(), salt, 1024);

        user.setPassword(md5Hash.toHex());
        System.out.println(user);
    }
}
